ASP.NET Core Blazor | Data from two tables in DataGrid
In this video we will discuss how to retrieve and display data from two or more related tables in a DatGrid.
Database table relationships
The following are the different types of relationships between database tables.
- One to One
- One to Many
- Many to Many
Consider the following 3 tables - Employees, Salaries and Departments
- We have a one-to-one relationship between
Employees
andSalaries
andEmployees
andDepartments
tables. DeptId
inEmployees
table is a foreign key referencingId
column inDepartments
tableSalaryId
inEmployees
table is a foreign key referencingId
column inSalaries
table
Displaying foreign key data in datagrid
- We wan to display
DepartmentName
in the DataGrid along with employee firstname, lastname etc. DepartmentName
is present in theDepartments
table and it is linked to theEmployees
table through the foreign keyDeptId
.- So to display
DepartmentName
in the DataGrid we use<GridForeignColumn>
component.
- ForeignDataSource - Defines the foreign data.
- Field - Defines the mapping column name to the foreign data.
- ForeignKeyValue - Defines the display field from the foreign data.
Complete Example (All CRUD operations supported)
© 2020 Pragimtech. All Rights Reserved.